"""
把字符串aaabbccd这种形式的字符串压缩成a3b2c2d1这总形式

f = a
count = 1

result = f+count
"""
s = "aaabbccdddeeffaaasss"
f = s[0]
count = 1
result = ""
for i in range(1, len(s)):  # 循环字符串的索引
    if s[i] == f:
        count += 1
    else:
        result += f + str(count)  # 记录f和count
        f = s[i]  # 更换f 和 count
        count = 1
result += f + str(count)
print(result)

"""
把字符串a3b2c2d1这种形式的字符串压缩成aaabbccd这总形式
"""
s = "a3b2c2d1e9b5c9"
f = s[0]
count = s[1]
result = ""
for i in range(len(s)):
    count = 0
    if s[i].isalpha():  # 判断是不是字母
        f = s[i]
        print(f)
    if s[i].isdigit():  # 判断是不是数字
        count = s[i]
    result += f * int(count)
print(result)
